<include file="Public:header"/>

<div class="cat">
<h2>添加新字段</h2>
<form method="POST" action="__URL__/add_value">
<table id="add_new" border="1" bordercolor="#DDDFFF" width="100%" style="border-collapse: collapse" cellpadding="5">
	<tr>
		<td align="right">模型：</td>
		<td><select size="1" name="model_id">
	<volist name="model" id="model">
	  <if  condition="$model.model_id eq $choose">
	     <option value="{$model.model_id}" selected>{$model.model_name}</option>
	  </if>
	</volist>
	</select>
	</td>
	</tr>
	<tr>
		<td align="right">类型：</td>
		<td>
		<select size="1" name="leixing">
	       <option value="a">文本框</option>
	       <option value="b">下拉框</option>
	</select>
		</td>
	</tr>
	<tr>
		<td align="right">字段名称：</td>
		<td><input type="text" name="value_name" size="20">如：颜色</td>
	</tr>
</table>
<div style="width:200px;margin:0 auto;"><input type="submit" value="添加" name="B1"></div>
</form>
</div>



<div class="cat">
<h2>已添加字段</h2>
<table bordercolor="#DDDFFF" border="1" width="100%" style="border-collapse: collapse" cellpadding="3">
	<tr height="17" align="center">
		<td class="title" width="150">字段</td>
        <td class="title">字段值</td>
		<td class="title" width="40">删除</td>
		
	</tr>
<volist name="mod_list" id="mod_list">
	<tr height="20" bgcolor="#F1F5FA" class="cat_list">
		<td width="150">
		<input type="text" name="pdt_id[]" value="{$mod_list.id}" style="display:none">
		<input type="text" name="pdt_name[]" value="{$mod_list.value_name}">
		</td>
        <td>
<if condition="$mod_list.leixing neq 'a'">
		<input type="text" name="pdt_value[]" value="{$mod_list.pdt_key}" size="100">用英文,隔开
</if>
		</td>
		<td width="40" align="center"><a href="javascript:;" onclick="del({$mod_list.id})"><img alt="删除" src="__APP__/statics/icons/icon_delete.gif"></a></td>	
	</tr>
</volist>
</table>
<div id="save"><input id="save_m" type="button" value="保存更改"></div>
</div>



<script>
$(function(){
    $("[name=leixing]").change(function(){
	    var type=$(this).val();
		if(type=='b'||type=='c'){
		   $(".xiala").empty();
		   $("<tr class='xiala'><td align='right'>选择值：</td><td><textarea rows='5' name='value_key' cols='20'></textarea></td></tr>").appendTo($("#add_new"));
	    }else{
		   $(".xiala").empty();
		}
	})

	$("#save").click(function(){
              var pdt_id=[];
			  $("[name='pdt_id[]']").each(function(){pdt_id.push($(this).val());}); 
			   var pdt_name=[];
			  $("[name='pdt_name[]']").each(function(){pdt_name.push($(this).val());}); 
			  var pdt_value=[];
			  $("[name='pdt_value[]']").each(function(){pdt_value.push($(this).val());}); 

			   $.ajax({
			         type:"POST",
					 url:"__URL__/cg_pdt_value",
					 dataType:"html",
					 data:{'pdt_id':pdt_id,'pdt_name':pdt_name,'pdt_value':pdt_value},
					 success:function(data){
						location.reload();
					 }
			   })
	})
})

function del(t){
    var id=t;
	if(confirm('你确认删除此属性吗？')) {
		$.ajax({
			 type:"GET",
			 url:"__URL__/del_pdt",
			 dataType:"json",
			 data:{'id':id},
			 success:function(data){
			 }
		})
		location.reload();
	}
}
</script>